#include <curses.h>
#include "../Headers/config.h"
#include "mods/mod.h"
#include "mods/an.h"
#include "mods/ws.h"
#include "mods/settings.h"
#include "gui.window.h"
#include "gui.button.h"
#include "gui.menu.h"
#include "gui.text.h"
#include "gui.browser.h"

using namespace TOB;

int main(int argc, char *argv[]) {
  String temp;
  Config _config(CONFIG);
  Config _lang(_config["lang"]);
  Config _ws_code(_config["ws-code"]);

  UIWindow::init();

  std::string str = CONVERT(_config["server-NS"]);
  Nameserver _ns(str);
  if(!_ns.isConnected()) {
    UIWindow window(0, 0, 0, 0);
    window.putString(_lang["ns-doesnt-respond"]);
    window.putChar('\n');
    window.putString(_lang["any-key"]);
    window.getChar();
    UIWindow::end(); 
    return -1;
  }

  UIConfig config = {_config, _lang, _ws_code, _ns, 15, 0};

  config.offsetX = 18;
  config.offsetY = 0;
  
  UI_AN an(config);
  UI_Settings settings(config);
  UI_WS ws(config);
  an.run();

  UIWindow welcome(config.offsetX, 0, 0, 0);
  temp = config.lang["tower-of-babel"];
  welcome.setCursor(1, 1);
  welcome.putString(temp);
  temp = config.lang["welcome-adm"];
  welcome.setCursor(1, 3);
  welcome.putString(temp);
  welcome.dispose();

  UIMenu menu(0, 0, config.offsetX, 0);
  menu.insert(config.lang["user-management"], [](){});
  menu.insert(config.lang["settings"], [&](){ settings.run(); });
  menu.insert(config.lang["quit"], [&](){ menu.running = false; });
  menu.focus();

  UIWindow::end();
  return 0;
}
